/*
 * @Author: 岸舟
 * @Date: 2020-09-22 14:15:23
 * @LastEditors: 岸舟
 * @LastEditTime: 2020-09-23 20:23:44
 * @Description: 
 */
/*
 * @Author: 岸舟
 * @Date: 2020-09-22 10:53:23
 * @LastEditors: 岸舟
 * @LastEditTime: 2020-09-23 10:52:17
 * @Description: 
 */
import apis from '../../http/apis/apis'

export default {
    namespaced: true,
    state: {
        currentUser: {},
        isCollapse: false,
        nowBreadcrumb: [],
        breadcrumbDate: [{
            key: 'system',
            name: '系统',
            path: 'system',
            children: [{
                key: 'admin',
                name: "用户管理",
                path: "admin",
                children: [{
                    key: "adduser",
                    name: "新增用户",
                    path: "adduser",
                },{
                    key: "userslist",
                    name: "用户列表",
                    path: "userslist"
                }]
            },{
                key: 'insureOrder',
                name: "订单管理",
                path: "insureOrder"
            },{
                key: 'insureProduct',
                name: "产品管理",
                path: "insureProduct",
                children: [{
                    key: "getItems",
                    name: "所有保险产品",
                    path: "getItems",
                },{
                    key: "AddItem",
                    name: "新增保险产品",
                    path: "AddItem"
                }]
            },{
                key: 'ClaimOrder',
                name: "理赔管理",
                path: "ClaimOrder",
                children: [{
                    key: "getClaims",
                    name: "待审核理赔",
                    path: "getClaims",
                },{
                    key: "addCompensation",
                    name: "新增理赔",
                    path: "addCompensation"
                },{
                    key: "getCompensations",
                    name: "查询理赔",
                    path: "getCompensations"
                }]
            },{
                key: 'insureSort',
                name: "保险分类",
                path: "insureSort"
            },{
                key: 'clients',
                name: "顾客管理",
                path: "clients"
            },{
                key: 'UserCenter',
                name: "个人中心",
                path: "UserCenter",
                children: [{
                    key: "modData",
                    name: "基本资料",
                    path: "modData",
                }]
            }]
        }]
    },
    mutations: {
        switchIsCollapse(state) {
            state.isCollapse = !state.isCollapse
        },
        setNowBreadcrumb(state, key) {
            const data = state.breadcrumbDate;
            let strArr = [];
            let isOk = false;
            //遍历对象组
            function createMowBreadcrumb(data, key) {
                for (const item of data) {
                    strArr.push(item);
                    if (item.key == key) {
                        isOk = true;
                        return;
                    } else {
                        if (item.children && item.children.length > 0) {
                            createMowBreadcrumb(item.children, key);
                            if (isOk) return;
                        }
                    }
                    strArr.pop();
                }
            }
            createMowBreadcrumb(data, key);

            state.nowBreadcrumb = [];

            strArr.reduce((url, item) => {
                let path = url + '/' + item.path;
                state.nowBreadcrumb.push({
                    name: item.name,
                    path
                })
                return path;
            }, "");

        },
        changeCurrentUser(state, val) {
            state.currentUser = val
        }
    },
    actions: {


    }
}